// Copyright (C) 2022 Linlexiao
#include "importproblemdialog.h"

#include <QByteArray>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>

ImportProblemDialog::ImportProblemDialog() {
    resize(800, 600);
    setStyleSheet("*{font:16pt 微软雅黑}");
    setWindowTitle("导入问题");
    setWindowIcon(QIcon(":/src/img/icon.png"));
    auto mainLayout = new QVBoxLayout();
    auto lb = new QLabel("输入问题代码:", this);
    mainLayout->addWidget(lb);
    edit = new QTextEdit(this);
    auto btn1 = new QPushButton("取消", this);
    connect(btn1, &QPushButton::clicked, this, &QDialog::reject);
    auto btn2 = new QPushButton("确定", this);
    btn2->setFocus();
    btn2->setDefault(1);
    connect(btn2, &QPushButton::clicked, this, &ImportProblemDialog::onOk);
    auto layout2 = new QHBoxLayout();
    mainLayout->addWidget(edit);
    layout2->addWidget(btn1);
    layout2->addWidget(btn2);
    mainLayout->addLayout(layout2);
    setLayout(mainLayout);
}

void ImportProblemDialog::onOk() {
    code = QString(QByteArray::fromBase64(edit->toPlainText().toUtf8()));
    accept();
}
